﻿using KZ.Express.ENT;
using KZ.Express.Presenter;
using KZ.Express.Resource;
using KZ.Utilities;
using System;
using System.Data;

namespace KZ.Express.Order.Order
{
    public partial class OrderDetailView : FormBase, IOrderDetailView
    {
        #region Private Variables

        private new OrderDetailPresenter _presenter;

        #endregion Private Variables

        #region Private Methods

        private void OrderDetailView_Load(object sender, EventArgs e)
        {
            LoadCarrier();
            LoadCustomer();
            LoadCountry();
            LoadData();
        }

        private void cmbCarrierID_SelectedValueChanged(object sender, EventArgs e)
        {
            LoadSupplier();
            LoadOriginalPriceList();
            LoadCustomerPriceList();
            ComputeStandardPrice();
            ComputeVNDStandardPrice();
        }

        private void cmbSupplierID_SelectedValueChanged(object sender, EventArgs e)
        {
            LoadOriginalPriceList();
            ComputeStandardPrice();
            ComputeVNDStandardPrice();
        }

        private void cmbCustomerID_SelectedValueChanged(object sender, EventArgs e)
        {
            LoadCustomerPriceList();
            ComputeListPrice();
            ComputeVNDListPrice();
        }

        private void cmbCountryID_SelectedValueChanged(object sender, EventArgs e)
        {
            ComputeStandardPrice();
            ComputeListPrice();
            ComputeVNDStandardPrice();
            ComputeVNDListPrice();
        }

        private void cmbOriginalPriceListID_SelectedValueChanged(object sender, EventArgs e)
        {
            ComputeStandardPrice();
            ComputeVNDStandardPrice();
        }

        private void cmbCustomerPriceListID_SelectedValueChanged(object sender, EventArgs e)
        {
            ComputeListPrice();
            ComputeVNDListPrice();
        }

        private void txtWeight_TextChanged(object sender, EventArgs e)
        {
            ComputeStandardPrice();
            ComputeListPrice();
            ComputeVNDStandardPrice();
            ComputeVNDListPrice();
        }

        private void txtListPrice_TextChanged(object sender, EventArgs e)
        {
            ComputeVNDStandardPrice();
        }

        private void txtStandardPrice_TextChanged(object sender, EventArgs e)
        {
            ComputeVNDListPrice();
        }

        /// <summary>
        /// compute vndlistprice base on percent
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void txtVNDListPercent_TextChanged(object sender, EventArgs e)
        {
            int decimalDegit = Utility.Info.NumberFormat.CurrencyDecimalDigits;
            Utility.Info.NumberFormat.CurrencyDecimalDigits = 0;
            try
            {
                decimal? listPrice = Utility.DecimalNParse(txtListPrice.Text);
                decimal vat = Utility.DecimalParse(txtVAT2.Text);
                decimal fuel = Utility.DecimalParse(txtFuel2.Text);
                decimal? rate = Utility.DecimalNParse(txtRate.Text);
                decimal vndListPercent = Utility.DecimalParse(txtVNDListPercent.Text);
                if (listPrice.HasValue && rate.HasValue)
                {
                    decimal vnd = ((listPrice * (1 + fuel / 100) * (1 + vat / 100)) * rate).Value;
                    vnd *= vndListPercent / 100;

                    txtVNDListOptional.Text = Utility.CurrencyParse(vnd, Utility.Info);
                }
            }
            finally
            {
                Utility.Info.NumberFormat.CurrencyDecimalDigits = decimalDegit;
            }
        }

        private void txtVNDListOptional_TextChanged(object sender, EventArgs e)
        {
            ComputeVNDListPrice();
        }

        private void txtVAT_TextChanged(object sender, EventArgs e)
        {
            ComputeVNDStandardPrice();
        }

        private void txtVAT2_TextChanged(object sender, EventArgs e)
        {
            ComputeVNDListPrice();
        }

        private void txtFuel_TextChanged(object sender, EventArgs e)
        {
            ComputeVNDStandardPrice();
        }

        private void txtFuel2_TextChanged(object sender, EventArgs e)
        {
            ComputeVNDListPrice();
        }

        private void txtRate_TextChanged(object sender, EventArgs e)
        {
            ComputeVNDStandardPrice();
            ComputeVNDListPrice();
        }

        private void txtWeight_Leave(object sender, EventArgs e)
        {
            txtWeight.TextChanged -= txtWeight_TextChanged;

            int numberDigit = Utility.Info.NumberFormat.NumberDecimalDigits;
            Utility.Info.NumberFormat.NumberDecimalDigits = 1;
            try
            {
                decimal? value = Utility.DecimalNParse(txtWeight.Text);
                txtWeight.Text = Utility.NumberParse(value, Utility.Info);
            }
            finally
            {
                Utility.Info.NumberFormat.NumberDecimalDigits = numberDigit;
                txtWeight.TextChanged += txtWeight_TextChanged;
            }
        }

        private void txtStandardPrice_Leave(object sender, EventArgs e)
        {
            txtStandardPrice.TextChanged -= txtStandardPrice_TextChanged;
            try
            {
                decimal? value = Utility.DecimalNParse(txtStandardPrice.Text);
                txtStandardPrice.Text = Utility.CurrencyParse(value, Utility.Info);
            }
            finally
            {
                txtStandardPrice.TextChanged += txtStandardPrice_TextChanged;
            }
        }

        private void txtListPrice_Leave(object sender, EventArgs e)
        {
            txtListPrice.TextChanged -= txtListPrice_TextChanged;
            try
            {
                decimal? value = Utility.DecimalNParse(txtListPrice.Text);
                txtListPrice.Text = Utility.CurrencyParse(value, Utility.Info);
            }
            finally
            {
                txtListPrice.TextChanged += txtListPrice_TextChanged;
            }
        }

        private void txtCost_Leave(object sender, EventArgs e)
        {
            decimal? value = Utility.DecimalNParse(txtCost.Text);
            txtCost.Text = Utility.CurrencyParse(value, Utility.Info);
        }

        private void txtRate_Leave(object sender, EventArgs e)
        {
            txtRate.TextChanged -= txtRate_TextChanged;

            int decimalDegit = Utility.Info.NumberFormat.CurrencyDecimalDigits;
            Utility.Info.NumberFormat.CurrencyDecimalDigits = 0;
            try
            {
                decimal? value = Utility.DecimalNParse(txtRate.Text);
                txtRate.Text = Utility.CurrencyParse(value, Utility.Info);
            }
            finally
            {
                Utility.Info.NumberFormat.CurrencyDecimalDigits = decimalDegit;
                txtRate.TextChanged += txtRate_TextChanged;
            }
        }

        private void txtVNDStandardPrice_Leave(object sender, EventArgs e)
        {
            int decimalDegit = Utility.Info.NumberFormat.CurrencyDecimalDigits;
            Utility.Info.NumberFormat.CurrencyDecimalDigits = 0;
            try
            {
                decimal? value = Utility.DecimalNParse(txtVNDStandardPrice.Text);
                txtVNDStandardPrice.Text = Utility.CurrencyParse(value, Utility.Info);
            }
            finally
            {
                Utility.Info.NumberFormat.CurrencyDecimalDigits = decimalDegit;
            }
        }

        private void txtVNDListPrice_Leave(object sender, EventArgs e)
        {
            int decimalDegit = Utility.Info.NumberFormat.CurrencyDecimalDigits;
            Utility.Info.NumberFormat.CurrencyDecimalDigits = 0;
            try
            {
                decimal? value = Utility.DecimalNParse(txtVNDListPrice.Text);
                txtVNDListPrice.Text = Utility.CurrencyParse(value, Utility.Info);
            }
            finally
            {
                Utility.Info.NumberFormat.CurrencyDecimalDigits = decimalDegit;
            }
        }

        private void txtVNDListOptional_Leave(object sender, EventArgs e)
        {
            txtVNDListOptional.TextChanged -= txtVNDListOptional_TextChanged;
            int decimalDegit = Utility.Info.NumberFormat.CurrencyDecimalDigits;
            Utility.Info.NumberFormat.CurrencyDecimalDigits = 0;
            try
            {
                decimal? value = Utility.DecimalNParse(txtVNDListOptional.Text);
                txtVNDListOptional.Text = Utility.CurrencyParse(value, Utility.Info);
            }
            finally
            {
                Utility.Info.NumberFormat.CurrencyDecimalDigits = decimalDegit;
                txtVNDListOptional.TextChanged += txtVNDListOptional_TextChanged;
            }
        }

        protected override void LoadData()
        {
            try
            {
                switch (base.Action)
                {
                    case ActionName.Insert:
                        break;

                    case ActionName.Update:
                        _presenter.LoadEntity();
                        break;
                }
            }
            catch (BusinessLogicException ex)
            {
                SetMessage(ex.Message, false);
            }
        }

        private void LoadCarrier()
        {
            try
            {
                cmbCarrierID.SelectedValueChanged -= cmbCarrierID_SelectedValueChanged;
                Global.LoadComboBox(cmbCarrierID, base._presenter.LoadForCMB<CarrierENT>(null));
            }
            catch (BusinessLogicException ex)
            {
                SetMessage(ex.Message, false);
            }
            finally
            {
                cmbCarrierID.SelectedValueChanged += cmbCarrierID_SelectedValueChanged;
            }
        }

        private void LoadSupplier()
        {
            try
            {
                cmbSupplierID.SelectedValueChanged -= cmbSupplierID_SelectedValueChanged;
                int carrierID = Utility.IntParse(cmbCarrierID.SelectedValue);

                SearchCriteria search = new SearchCriteria();
                search.Add("CarrierID", carrierID);
                DataTable dt = base._presenter.LoadForCMB<SupplierENT>(search);
                Global.LoadComboBox(cmbSupplierID, dt);

                if (dt.Rows.Count > 1)
                    cmbSupplierID.SelectedIndex = 1;
            }
            catch (BusinessLogicException ex)
            {
                SetMessage(ex.Message, false);
            }
            finally
            {
                cmbSupplierID.SelectedValueChanged += cmbSupplierID_SelectedValueChanged;
            }
        }

        private void LoadCustomer()
        {
            try
            {
                cmbCustomerID.SelectedValueChanged -= cmbCustomerID_SelectedValueChanged;
                SearchCriteria search = new SearchCriteria();
                search.Add("IsCustomer", 1);
                Global.LoadComboBox(cmbCustomerID, base._presenter.LoadForCMB<CustomerENT>(search));
            }
            catch (BusinessLogicException ex)
            {
                SetMessage(ex.Message, false);
            }
            finally
            {
                cmbCustomerID.SelectedValueChanged += cmbCustomerID_SelectedValueChanged;
            }
        }

        private void LoadCountry()
        {
            try
            {
                cmbCountryID.SelectedValueChanged -= cmbCountryID_SelectedValueChanged;
                Global.LoadComboBox(cmbCountryID, base._presenter.LoadForCMB<CountryENT>(null));
                cmbCountryID.SelectedValueChanged += cmbCountryID_SelectedValueChanged;
            }
            catch (BusinessLogicException ex)
            {
                SetMessage(ex.Message, false);
            }
        }

        private void LoadOriginalPriceList()
        {
            try
            {
                cmbOriginalPriceListID.SelectedValueChanged -= cmbOriginalPriceListID_SelectedValueChanged;
                int carrierID = Utility.IntParse(cmbCarrierID.SelectedValue);
                int supplierID = Utility.IntParse(cmbSupplierID.SelectedValue);

                DataTable dt = _presenter.LoadOriginalPriceList(carrierID, supplierID, dtpOrderDate.Value);
                Global.LoadComboBox(cmbOriginalPriceListID, dt);

                if (dt.Rows.Count > 1)
                    cmbOriginalPriceListID.SelectedIndex = 1;
            }
            catch (BusinessLogicException ex)
            {
                SetMessage(ex.Message, false);
            }
            finally
            {
                cmbOriginalPriceListID.SelectedValueChanged += cmbOriginalPriceListID_SelectedValueChanged;
            }
        }

        private void LoadCustomerPriceList()
        {
            try
            {
                cmbCustomerPriceListID.SelectedValueChanged -= cmbCustomerPriceListID_SelectedValueChanged;
                int carrierID = Utility.IntParse(cmbCarrierID.SelectedValue);
                int supplierID = Utility.IntParse(cmbSupplierID.SelectedValue);
                int customerID = Utility.IntParse(cmbCustomerID.SelectedValue);

                DataTable dt = _presenter.LoadCustomerPriceList(carrierID, supplierID, customerID, dtpOrderDate.Value);
                Global.LoadComboBox(cmbCustomerPriceListID, dt);

                if (dt.Rows.Count > 1)
                    cmbCustomerPriceListID.SelectedIndex = 1;
            }
            catch (BusinessLogicException ex)
            {
                SetMessage(ex.Message, false);
            }
            finally
            {
                cmbCustomerPriceListID.SelectedValueChanged += cmbCustomerPriceListID_SelectedValueChanged;
            }
        }

        private void ComputeStandardPrice()
        {
            try
            {
                int? oriPriceListID = Utility.IntNParse(cmbOriginalPriceListID.SelectedValue);
                int? carrierID = Utility.IntNParse(cmbCarrierID.SelectedValue);
                int? countryID = Utility.IntNParse(cmbCountryID.SelectedValue);
                string type = cmbType.Text;
                decimal? weight = Utility.DecimalNParse(txtWeight.Text);

                if (oriPriceListID.HasValue && carrierID.HasValue && countryID.HasValue && !String.IsNullOrEmpty(type) && weight.HasValue)
                {
                    decimal standardPrice = _presenter.LoadPrice(oriPriceListID.Value, carrierID.Value, countryID.Value, type, weight.Value);
                    txtStandardPrice.Text = Utility.CurrencyParse(standardPrice, Utility.Info);
                }
                else
                    txtStandardPrice.Text = String.Empty;
            }
            catch (BusinessLogicException ex)
            {
                SetMessage(ex.Message, false);
            }
        }

        private void ComputeListPrice()
        {
            try
            {
                int? cusPriceListID = Utility.IntNParse(cmbCustomerPriceListID.SelectedValue);
                int? carrierID = Utility.IntNParse(cmbCarrierID.SelectedValue);
                int? countryID = Utility.IntNParse(cmbCountryID.SelectedValue);
                string type = cmbType.Text;
                decimal? weight = Utility.DecimalNParse(txtWeight.Text);

                if (cusPriceListID.HasValue && carrierID.HasValue && countryID.HasValue && !String.IsNullOrEmpty(type) && weight.HasValue)
                {
                    decimal listPrice = _presenter.LoadPrice(cusPriceListID.Value, carrierID.Value, countryID.Value, type, weight.Value);
                    txtListPrice.Text = Utility.CurrencyParse(listPrice, Utility.Info);
                }
                else
                    txtListPrice.Text = String.Empty;
            }
            catch (BusinessLogicException ex)
            {
                SetMessage(ex.Message, false);
            }
        }

        private void ComputeVNDStandardPrice()
        {
            int decimalDegit = Utility.Info.NumberFormat.CurrencyDecimalDigits;
            Utility.Info.NumberFormat.CurrencyDecimalDigits = 0;
            try
            {
                decimal? standardPrice = Utility.DecimalNParse(txtStandardPrice.Text);
                decimal vat = Utility.DecimalParse(txtVAT.Text);
                decimal fuel = Utility.DecimalParse(txtFuel.Text);
                decimal? rate = Utility.DecimalNParse(txtRate.Text);
                if (standardPrice.HasValue && rate.HasValue)
                {
                    decimal vnd = ((standardPrice * (1 + fuel / 100) * (1 + vat / 100)) * rate).Value;
                    txtVNDStandardPrice.Text = Utility.CurrencyParse(vnd, Utility.Info);
                }
                else
                    txtVNDStandardPrice.Text = String.Empty;
            }
            finally
            {
                Utility.Info.NumberFormat.CurrencyDecimalDigits = decimalDegit;
            }
        }

        private void ComputeVNDListPrice()
        {
            int decimalDegit = Utility.Info.NumberFormat.CurrencyDecimalDigits;
            Utility.Info.NumberFormat.CurrencyDecimalDigits = 0;
            try
            {
                decimal? listPrice = Utility.DecimalNParse(txtListPrice.Text);
                decimal vndListOptional = Utility.DecimalParse(txtVNDListOptional.Text);
                decimal vat = Utility.DecimalParse(txtVAT2.Text);
                decimal fuel = Utility.DecimalParse(txtFuel2.Text);
                decimal? rate = Utility.DecimalNParse(txtRate.Text);
                if (listPrice.HasValue && rate.HasValue)
                {
                    decimal vnd = ((listPrice * (1 + fuel / 100) * (1 + vat / 100)) * rate + vndListOptional).Value;
                    txtVNDListPrice.Text = Utility.CurrencyParse(vnd, Utility.Info);
                }
                else
                    txtVNDListPrice.Text = String.Empty;
            }
            finally
            {
                Utility.Info.NumberFormat.CurrencyDecimalDigits = decimalDegit;
            }
        }

        #endregion Private Methods

        #region Constructors

        public OrderDetailView()
        {
            InitializeComponent();
            base.ObjectID = (int)Objects.MenuOrder;

            cmbSupplierID.DisplayColumns.Add("PartnerCode", "Mã account");
            cmbSupplierID.DisplayColumns.Add("PartnerName", "Tên acount");
            cmbCustomerID.DisplayColumns.Add("PartnerCode", "Mã KH");
            cmbCustomerID.DisplayColumns.Add("PartnerName", "Tên KH");
            cmbOriginalPriceListID.DisplayColumns.Add("PriceListCode", "Mã bảng giá");
            cmbOriginalPriceListID.DisplayColumns.Add("PriceListName", "Tên bảng giá");
            cmbCustomerPriceListID.DisplayColumns.Add("PriceListCode", "Mã bảng giá");
            cmbCustomerPriceListID.DisplayColumns.Add("PriceListName", "Tên bảng giá");
            cmbCountryID.DisplayColumns.Add("CountryCode", "Mã nước");
            cmbCountryID.DisplayColumns.Add("CountryName", "Tên tên nước");
            cmbSupplierID.DropDownWidth = 300;
            cmbOriginalPriceListID.DropDownWidth = 300;
            cmbCustomerPriceListID.DropDownWidth = 300;
            cmbCountryID.DropDownWidth = 300;

            base._presenter = _presenter = new OrderDetailPresenter(this);
            bool isViewOriginal = _presenter.IsPermission((int)Objects.MenuOrder, (int)Permissions.ViewOriginal);

            if (!isViewOriginal)
            {
                lblStandardPrice.Visible = lblStandardPriceSymbol.Visible = txtStandardPrice.Visible = false;
                lblVNDStandardPrice.Visible = lblVNDStandardPriceSymbol.Visible = txtVNDStandardPrice.Visible = false;

                lblListPrice.Location = lblStandardPrice.Location;
                lblListPriceSymbol.Location = lblStandardPriceSymbol.Location;
                txtListPrice.Location = txtStandardPrice.Location;

                lblVNDListPrice.Location = lblVNDStandardPrice.Location;
                lblVNDListPriceSymbol.Location = lblVNDStandardPriceSymbol.Location;
                txtVNDListPrice.Location = txtVNDStandardPrice.Location;
            }

        }

        #endregion Constructors

        #region Public Properties

        public int OrderNumberLength
        {
            get
            {
                DataRowView row = cmbCarrierID.SelectedItem as DataRowView;
                if (row != null)
                    return Utility.IntParse(row["OrderNumberLength"]);
                return 0;
            }
        }

        public override EntityBase Entity
        {
            get
            {
                OrderENT order = new OrderENT();
                order.OrderID = base.EntityID;
                order.OrderDate = dtpOrderDate.Value;
                order.OrderNumber = txtOrderNumber.Text;
                order.CarrierID = Utility.IntNParse(cmbCarrierID.SelectedValue);
                order.SupplierID = Utility.IntNParse(cmbSupplierID.SelectedValue);
                order.CustomerID = Utility.IntNParse(cmbCustomerID.SelectedValue);
                order.CountryID = Utility.IntNParse(cmbCountryID.SelectedValue);
                order.Type = cmbType.Text;
                order.OriginalPriceListID = Utility.IntNParse(cmbOriginalPriceListID.SelectedValue);
                order.CustomerPriceListID = Utility.IntNParse(cmbCustomerPriceListID.SelectedValue);
                order.Weight = Utility.DecimalNParse(txtWeight.Text);
                order.StandardPrice = Utility.DecimalNParse(txtStandardPrice.Text);
                order.ListPrice = Utility.DecimalNParse(txtListPrice.Text);
                order.Cost = Utility.DecimalNParse(txtCost.Text);
                order.VNDListOptional = Utility.DecimalNParse(txtVNDListOptional.Text, Utility.Info);

                if (txtVAT.Text == "0")
                    order.OriVAT = 0;
                else
                    order.OriVAT = Utility.DecimalNParse(txtVAT.Text);
                if (txtVAT2.Text == "0")
                    order.VAT = 0;
                else
                    order.VAT = Utility.DecimalNParse(txtVAT2.Text);

                if (txtFuel.Text == "0")
                    order.OriFuel = 0;
                else
                    order.OriFuel = Utility.DecimalNParse(txtFuel.Text);
                if (txtFuel2.Text == "0")
                    order.Fuel = 0;
                else
                    order.Fuel = Utility.DecimalNParse(txtFuel2.Text);

                if (txtRate.Text == "0")
                    order.Rate = 0;
                else
                    order.Rate = Utility.DecimalNParse(txtRate.Text);

                order.VNDStandardPrice = Utility.DecimalNParse(txtVNDStandardPrice.Text);
                order.VNDListPrice = Utility.DecimalNParse(txtVNDListPrice.Text);
                order.Description = txtDescription.Text;
                order.CreatedBy = UserENT.USERID;
                order.UpdatedBy = UserENT.USERID;

                return order;
            }
            set
            {
                int numberDigit = Utility.Info.NumberFormat.NumberDecimalDigits;
                int currencyDegit = Utility.Info.NumberFormat.CurrencyDecimalDigits;
                try
                {
                    cmbCountryID.SelectedValueChanged -= cmbCountryID_SelectedValueChanged;
                    cmbOriginalPriceListID.SelectedValueChanged -= cmbOriginalPriceListID_SelectedValueChanged;
                    cmbCustomerPriceListID.SelectedValueChanged -= cmbCustomerPriceListID_SelectedValueChanged;
                    txtWeight.TextChanged -= txtWeight_TextChanged;
                    txtStandardPrice.TextChanged -= txtStandardPrice_TextChanged;
                    txtListPrice.TextChanged -= txtListPrice_TextChanged;
                    txtRate.TextChanged -= txtRate_TextChanged;
                    txtVAT.TextChanged -= txtVAT_TextChanged;
                    txtVAT2.TextChanged -= txtVAT2_TextChanged;
                    txtFuel.TextChanged -= txtFuel_TextChanged;
                    txtFuel2.TextChanged -= txtFuel2_TextChanged;
                    txtVNDListPercent.TextChanged -= txtVNDListPercent_TextChanged;
                    txtVNDListOptional.TextChanged -= txtVNDListOptional_TextChanged;


                    OrderENT order = value != null ? value as OrderENT : new OrderENT();
                    dtpOrderDate.Value = Utility.DateTimeParse(order.OrderDate);
                    txtOrderNumber.Text = order.OrderNumber;
                    cmbCarrierID.SelectedValue = Utility.IntParse(order.CarrierID);
                    cmbSupplierID.SelectedValue = Utility.IntParse(order.SupplierID);
                    cmbCustomerID.SelectedValue = Utility.IntParse(order.CustomerID);
                    cmbCountryID.SelectedValue = Utility.IntParse(order.CountryID);
                    cmbType.Text = order.Type;
                    cmbOriginalPriceListID.SelectedValue = Utility.IntParse(order.OriginalPriceListID);
                    cmbCustomerPriceListID.SelectedValue = Utility.IntParse(order.CustomerPriceListID);
                    Utility.Info.NumberFormat.NumberDecimalDigits = 1;
                    txtWeight.Text = Utility.NumberParse(order.Weight, Utility.Info);
                    Utility.Info.NumberFormat.NumberDecimalDigits = 0;
                    txtStandardPrice.Text = Utility.CurrencyParse(order.StandardPrice, Utility.Info);
                    txtListPrice.Text = Utility.CurrencyParse(order.ListPrice, Utility.Info);
                    txtCost.Text = Utility.CurrencyParse(order.Cost, Utility.Info);
                    txtVAT.Text = Utility.NumberParse(order.OriVAT, Utility.Info);
                    txtVAT2.Text = Utility.NumberParse(order.VAT, Utility.Info);
                    txtFuel.Text = Utility.NumberParse(order.OriFuel, Utility.Info);
                    txtFuel2.Text = Utility.NumberParse(order.Fuel, Utility.Info);
                    Utility.Info.NumberFormat.NumberDecimalDigits = numberDigit;
                    Utility.Info.NumberFormat.CurrencyDecimalDigits = 0;
                    txtVNDListOptional.Text = Utility.CurrencyParse(order.VNDListOptional, Utility.Info);
                    txtRate.Text = Utility.CurrencyParse(order.Rate, Utility.Info);
                    txtVNDStandardPrice.Text = Utility.CurrencyParse(order.VNDStandardPrice, Utility.Info);
                    txtVNDListPrice.Text = Utility.CurrencyParse(order.VNDListPrice, Utility.Info);
                    txtDescription.Text = order.Description;
                }
                finally
                {
                    Utility.Info.NumberFormat.NumberDecimalDigits = numberDigit;
                    Utility.Info.NumberFormat.CurrencyDecimalDigits = currencyDegit;
                    cmbCountryID.SelectedValueChanged += cmbCountryID_SelectedValueChanged;
                    cmbOriginalPriceListID.SelectedValueChanged += cmbOriginalPriceListID_SelectedValueChanged;
                    cmbCustomerPriceListID.SelectedValueChanged += cmbCustomerPriceListID_SelectedValueChanged;
                    txtWeight.TextChanged += txtWeight_TextChanged;
                    txtStandardPrice.TextChanged += txtStandardPrice_TextChanged;
                    txtListPrice.TextChanged += txtListPrice_TextChanged;
                    txtRate.TextChanged += txtRate_TextChanged;
                    txtVAT.TextChanged += txtVAT_TextChanged;
                    txtVAT2.TextChanged += txtVAT2_TextChanged;
                    txtFuel.TextChanged += txtFuel_TextChanged;
                    txtFuel2.TextChanged += txtFuel2_TextChanged;
                    txtVNDListPercent.TextChanged += txtVNDListPercent_TextChanged;
                    txtVNDListOptional.TextChanged += txtVNDListOptional_TextChanged;
                }
            }
        }

        #endregion Public Properties
    }
}